package com.bys.admin.ai.mapper;

import java.util.*;

import com.bys.admin.ai.controller.vo.ChatMessagePageReqVO;
import com.bys.admin.ai.entity.Chat;
import com.bys.admin.ai.entity.ChatMessage;
import com.bys.vo.PageVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * AI Chat 消息 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface ChatMessageMapper extends MPJBaseMapper<ChatMessage> {

    default Page<ChatMessage> selectPage(ChatMessagePageReqVO reqVO) {
        return selectPage(new Page<ChatMessage>(reqVO.getPageNo(),reqVO.getPageSize()), new LambdaQueryWrapper<ChatMessage>()
                .eq(Objects.nonNull(reqVO.getChatId()),ChatMessage::getChatId, reqVO.getChatId())
                .eq(Objects.nonNull(reqVO.getReplyId()),ChatMessage::getReplyId, reqVO.getReplyId())
                .eq(Objects.nonNull(reqVO.getType()),ChatMessage::getType, reqVO.getType())
                .eq(Objects.nonNull(reqVO.getUserId()),ChatMessage::getUserId, reqVO.getUserId())
                .eq(Objects.nonNull(reqVO.getRoleId()),ChatMessage::getRoleId, reqVO.getRoleId())
                .eq(Objects.nonNull(reqVO.getSegmentIds()),ChatMessage::getSegmentIds, reqVO.getSegmentIds())
                .eq(Objects.nonNull(reqVO.getModel()),ChatMessage::getModel, reqVO.getModel())
                .eq(Objects.nonNull(reqVO.getModelId()),ChatMessage::getModelId, reqVO.getModelId())
                .eq(Objects.nonNull(reqVO.getContent()),ChatMessage::getContent, reqVO.getContent())
                .eq(Objects.nonNull(reqVO.getUseContext()),ChatMessage::getUseContext, reqVO.getUseContext())
                .orderByDesc(ChatMessage::getCreateTime));
    }
}